home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / idlelib / WindowList.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  3KB  |  114 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. from Tkinter import *
  5.  
  6. class WindowList:
  7.     
  8.     def __init__(self):
  9.         self.dict = { }
  10.         self.callbacks = []
  11.  
  12.     
  13.     def add(self, window):
  14.         window.after_idle(self.call_callbacks)
  15.         self.dict[str(window)] = window
  16.  
  17.     
  18.     def delete(self, window):
  19.         
  20.         try:
  21.             del self.dict[str(window)]
  22.         except KeyError:
  23.             pass
  24.  
  25.         self.call_callbacks()
  26.  
  27.     
  28.     def add_windows_to_menu(self, menu):
  29.         list = []
  30.         for key in self.dict.keys():
  31.             window = self.dict[key]
  32.             
  33.             try:
  34.                 title = window.get_title()
  35.             except TclError:
  36.                 continue
  37.  
  38.             list.append((title, window))
  39.         
  40.         list.sort()
  41.         for title, window in list:
  42.             menu.add_command(label = title, command = window.wakeup)
  43.         
  44.  
  45.     
  46.     def register_callback(self, callback):
  47.         self.callbacks.append(callback)
  48.  
  49.     
  50.     def unregister_callback(self, callback):
  51.         
  52.         try:
  53.             self.callbacks.remove(callback)
  54.         except ValueError:
  55.             pass
  56.  
  57.  
  58.     
  59.     def call_callbacks(self):
  60.         for callback in self.callbacks:
  61.             
  62.             try:
  63.                 callback()
  64.             continue
  65.             print 'warning: callback failed in WindowList', sys.exc_type, ':', sys.exc_value
  66.             continue
  67.  
  68.         
  69.  
  70.  
  71. registry = WindowList()
  72. add_windows_to_menu = registry.add_windows_to_menu
  73. register_callback = registry.register_callback
  74. unregister_callback = registry.unregister_callback
  75.  
  76. class ListedToplevel(Toplevel):
  77.     
  78.     def __init__(self, master, **kw):
  79.         Toplevel.__init__(self, master, kw)
  80.         registry.add(self)
  81.         self.focused_widget = self
  82.  
  83.     
  84.     def destroy(self):
  85.         registry.delete(self)
  86.         Toplevel.destroy(self)
  87.         if not registry.dict:
  88.             self.quit()
  89.         
  90.  
  91.     
  92.     def update_windowlist_registry(self, window):
  93.         registry.call_callbacks()
  94.  
  95.     
  96.     def get_title(self):
  97.         return self.wm_title()
  98.  
  99.     
  100.     def wakeup(self):
  101.         
  102.         try:
  103.             if self.wm_state() == 'iconic':
  104.                 self.wm_withdraw()
  105.                 self.wm_deiconify()
  106.             
  107.             self.tkraise()
  108.             self.focused_widget.focus_set()
  109.         except TclError:
  110.             pass
  111.  
  112.  
  113.  
  114.